<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\PositionField;
use App\Models\PositionList;
use Carbon\Carbon;
class Position extends Model
{
    //
    use SoftDeletes;
    
    protected $connection = 'mysql';
	
	public static $type = [ 1 => '首页', 2 => '手机站首页（wap.zhuoke.cn）', 3 => '艺术家频道' , 4 => '新闻频道' , 5 => '拍卖频道'  ];
	public static $pattern = [ 1 => '手动', 2 => '自动' ];
	public static $yesorno = [ 1 => '是', 0 => '否' ];
	public static $selectOrder = [ 1 => '按最新', 2 => '按热门', 3=> '按评论' ];
	public static $selectOrders = [ 1 => 'created_at', 2 => 'onclick', 3=> 'pl_count' ];
	public static $selectTime = [ 0 => '不限制', 1 => '1天内', 2=> '2天内', 3=> '1周内', 4=> '1月内', 5=> '3月内', 6=> '6个月内', 7=> '1年内' ];

	
	protected $casts = [
        'hand_setting' => 'json',
        'auto_setting' => 'json',
    ];
	//设置选择时间
	public static function selectTimes()
	{
		$now = Carbon::now();
		return [
			0 => '1972-01-01', 
			1 => $now->subDay()->toDateString(), 
			2=> $now->subDay(2)->toDateString(), 
			3=> $now->subWeek()->toDateString(), 
			4=> $now->subMonth()->toDateString(), 
			5=> $now->subMonth(3)->toDateString(), 
			6=> $now->subMonth(6)->toDateString(), 
			7=> $now->subYear()->toDateString()
		];
	}
	
	//字段关系
	public function fields()
	{
		return $this->hasMany(PositionField::class, 'position_id', 'id');
	}
	//获取手动列表
	public function hand_lists()
	{
		return $this->hasMany(PositionList::class, 'position_id', 'id')->orderBy('listorder', 'asc')->orderBy('id', 'DESC');
	}
}
